﻿@{
    ViewBag.Title = "全部文件";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using Wolfy.NetDisk.Site.Utils;
<style>
    .table tr th {
        background-color: #f3f3f4;
    }
</style>
<form method="post" enctype="multipart/form-data" id="mainform" action="../netdisk/PostedFile">

    <button class="btn btn-primary btn-margin-left-10" id="btnNewFolder">新建文件夹</button>
    <button class="btn btn-primary btn-margin-left-10" id="btnUploadFile">上传文件</button>
    <input type="file" style="display:none;" name="name" value="" id="fileUpload" />
    <div>
        <span><a href="javascript:void(0)" path="/" id="lnkPath">全部文件</a></span>
    </div>
    <table class="table sortable-list">
        <tr id="file-table-tr-header">

            <th><input type="checkbox" id="chkAll" class="check-mail">文件名</th>
            <th>大小</th>
            <th>修改日期</th>
        </tr>
        @foreach (var item in @ViewBag.user.Files as ICollection<Wolfy.NetDisk.Core.Model.File>)
        {
            <tr><td><input type="checkbox" id="chkAll" class="check-mail" /><img src="@item.Icon.Path" alt="@item.Name" /> @item.Name</td><td>@Extentions.ToMB(item.Size * 1.0)</td><td>@item.Dt</td></tr>

        }

    </table>
</form>
<script>
    $("#fileUpload").change(function () {
        $("#mainform").ajaxSubmit({
            url: "../netdisk/PostedFile",
            type: "post",
            target: "#file-table-tr-header",//刷新的区域
            data: { path: $("#lnkPath").attr("path") },
            dataType: "json",
            clearForm: true,       // clear all form fields after successful submit
            resetForm: true,       // reset the form after successful submit
            success: function (data) {
                console.log(data);
                data = JSON.parse(data);
                console.log(data);
                if (data._code == 200) {
                    $('<tr><td><input type="checkbox" id="chkAll" class="check-mail"/><img src="' + data._data.file.Icon + '" alt="' + data._data.file.Name + '" />' + data._data.file.Name + '</td><td>' + data._data.file.Size + '</td><td>' + data._data.file.Dt + '</td></tr>').appendTo($(".table"));
                };
            },
            error: function (aa) {
                console.log(aa);
            }
        });
        return false;
    });
    $("#btnUploadFile").on("click", function () {
        $("#fileUpload").click();
        return false;
    });
    $("#btnNewFolder").on("click", function () {

        return false;
    });
</script>
